package com.br.fmn.clubedoimovel.negocio.util;

import java.util.Locale;

import com.br.fmn.clubedoimovel.negocio.entidade.Coordinates;
import com.br.fmn.clubedoimovel.negocio.entidade.PlaceEntity;

public abstract class StringUtil {

	private static final String URL_ROUTE = "http://maps.google.com/maps?f=d&hl=en&"
			+ "saddr=%f,%f&daddr=%f,%f&ie=UTF8&0&om=0&" + "output=kml";

	/**
	 * Formatted URL with latitude and longitude of destination and origen.
	 * 
	 * @param coordinates
	 *            receiver four coordinates in a collection.
	 * @return return URL route formatted.
	 */
	public static String urlRout(Coordinates[] coordinates) {

		String urlformattedRout = String.format(Locale.US, URL_ROUTE,
				coordinates[0].getCoordinatesOrigin().getLatitude(),
				coordinates[0].getCoordinatesOrigin().getLongitude(),
				coordinates[0].getCoordinatesDestination().getLatitude(),
				coordinates[0].getCoordinatesDestination().getLongitude());

		return urlformattedRout;
	}

	public static String changeSpaceToPercentage(String string) {
		return string.replace(" ", "%");
	}

	/**
	 * Formatted URL with reference for place.
	 * 
	 * @param reference
	 *            for search place.
	 * @return
	 */
	public static String urlPlace(String reference) {

		String referenceFormatted = changeSpaceToPercentage(reference);

		String urlPlace = "https://maps.googleapis.com/maps/api/place/autocomplete/json?input="
				+ referenceFormatted
				+ "&types="
				+ PlaceEntity.TYPE
				+ "&region="
				+ PlaceEntity.REGION
				+ "&language="
				+ PlaceEntity.LANGUAGE
				+ "&sensor=true&key=" + PlaceEntity.PLACE_KEY + "";

		return urlPlace;
	}
}
